package com.ruoyi.jy.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jy.domain.Studentemployment;
import com.ruoyi.jy.service.IStudentemploymentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 就业管理Controller
 *
 * @author bilong
 * @date 2024-01-09
 */
@RestController
@RequestMapping("/studentemployment/studentemployment")
public class StudentemploymentController extends BaseController
{
    @Autowired
    private IStudentemploymentService studentemploymentService;

    /**
     * 查询就业管理列表
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Studentemployment studentemployment)
    {
        startPage();
        List<Studentemployment> list = studentemploymentService.selectStudentemploymentList(studentemployment);
        return getDataTable(list);
    }

    /**
     * 导出就业管理列表
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:export')")
    @Log(title = "就业管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Studentemployment studentemployment)
    {
        List<Studentemployment> list = studentemploymentService.selectStudentemploymentList(studentemployment);
        ExcelUtil<Studentemployment> util = new ExcelUtil<Studentemployment>(Studentemployment.class);
        util.exportExcel(response, list, "就业管理数据");
    }

    /**
     * 获取就业管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:query')")
    @GetMapping(value = "/{sid}")
    public AjaxResult getInfo(@PathVariable("sid") Long sid)
    {
        return success(studentemploymentService.selectStudentemploymentBySid(sid));
    }

    /**
     * 获取就业总人数
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:getStatCount')")
    @GetMapping(value = "/getStatCount")
    public AjaxResult getStatCount()
    {
        return success(studentemploymentService.getStatCount());
    }
    /**
     * 获取就业未就业占比人数
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:getGroupStat')")
    @GetMapping(value = "/getGroupStat")
    public AjaxResult getGroupStat()
    {
        return success(studentemploymentService.getGroupStat());
    }
    /**
     * 获取每个专业学生的性别人数
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:getStudentemploymentSpecilitySex')")
    @GetMapping(value = "/getStudentemploymentSpecilitySex")
    public AjaxResult getStudentemploymentSpecilitySex()
    {
        return success(studentemploymentService.getStudentemploymentSpecilitySex());
    }
    /**
     * 获取不同专业就业平均薪资
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:getStudentemploymentSpecilityMoney')")
    @GetMapping(value = "/getStudentemploymentSpecilityMoney")
    public AjaxResult getStudentemploymentSpecilityMoney()
    {
        return success(studentemploymentService.getStudentemploymentSpecilityMoney());
    }

    /**
     * 获取毕业总人数
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:getOutTimeCount')")
    @GetMapping(value = "/getOutTimeCount")
    public AjaxResult getOutTimeCount()
    {
        return success(studentemploymentService.getOutTimeCount());
    }


    /**
     * 新增就业管理
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:add')")
    @Log(title = "就业管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Studentemployment studentemployment)
    {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String s = sdf.format(date);
        String substring = studentemployment.getBirthday().substring(0, 10);
        studentemployment.setCreatetime(s.substring(0,10));
        studentemployment.setEtime(studentemployment.getEtime().substring(0,10));
        studentemployment.setIntime(studentemployment.getIntime().substring(0,10));
        studentemployment.setOuttime(studentemployment.getOuttime().substring(0,10));
        studentemployment.setBirthday(substring);
        return toAjax(studentemploymentService.insertStudentemployment(studentemployment));
    }

    /**
     * 修改就业管理
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:edit')")
    @Log(title = "就业管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Studentemployment studentemployment)
    {
        return toAjax(studentemploymentService.updateStudentemployment(studentemployment));
    }

    /**
     * 删除就业管理
     */
    @PreAuthorize("@ss.hasPermi('studentemployment:studentemployment:remove')")
    @Log(title = "就业管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sids}")
    public AjaxResult remove(@PathVariable Long[] sids)
    {
        return toAjax(studentemploymentService.deleteStudentemploymentBySids(sids));
    }
}
